//
//  LCMineInfoViewController.m
//  lechuang
//
//  Created by Mr_hi on 2023/3/25.
//  Copyright © 2023 Mooyi. All rights reserved.
//

#import "LCMineInfoViewController.h"
#import "LCMineService.h"
#import "LCUserModel.h"

@interface LCMineInfoViewController ()<GetImageDelegate>

@property (weak, nonatomic) IBOutlet UIView *headBgView;

@property (weak, nonatomic) IBOutlet UIImageView *thumbView;

@property (weak, nonatomic) IBOutlet UILabel *userIdLb;

@property (weak, nonatomic) IBOutlet UILabel *phoneLb;

@property (weak, nonatomic) IBOutlet UITextField *nickNameTfl;

@end

@implementation LCMineInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUI];
}

- (void)setUI {
    [self.headBgView whenTapped:^{
        [[GetImage shareUploadImage] showActionSheetInFatherViewController:self delegate:self whetherNeedEditMode:YES withOnlyPhone:NO];
    }];
    
    [self.thumbView sd_setImageWithURL:[LCFunction XWX_URLImg:self.dataMode.userthumb] placeholderImage:kGetImage(@"lc_mine_user_head")];
    self.userIdLb.text =  self.dataMode.userid;
    self.phoneLb.text = self.dataMode.usermobile;
    self.nickNameTfl.text = self.dataMode.nickname;
}

#pragma mark - GetImage-Delegate-选择图片的代理实现
-(void)getImageToActionWithImage:(UIImage *)image {
    [LCMineService changeThumbWithImg:image Block:^(BOOL isSuccess) {
        if (isSuccess) {
            self.thumbView.image = image;
        }
    }];
}

- (IBAction)confirmBtnAction:(UIButton *)sender {
    if (self.nickNameTfl.text == self.dataMode.nickname) {
        [self showSuccessText:@"修改昵称成功!"];
        [self.navigationController popViewControllerAnimated:YES];
    } else {
        if (self.nickNameTfl.text.length <= 0) {
            [self showErrorText:self.nickNameTfl.placeholder];
            [self.nickNameTfl becomeFirstResponder];
        } else {
            [LCMineService changeNickName:self.nickNameTfl.text Block:^(BOOL isSuccess) {
                if (!isSuccess) {
                    [self.nickNameTfl becomeFirstResponder];
                } else {
                    [self.navigationController popViewControllerAnimated:YES];
                }
            }];
        }
    }
}


- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


@end
